package com.example.seckillprovider.mapper;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.myshop.b2b.commonmodule.Goods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author likaiping
 */
@Mapper
public interface GoodsMapper{

    /**
     * 根据商品id查询库存
     * @param gid
     * @return
     */
    @Select("select stock from goods where gid=#{gid}")
    Integer getGoodsStock(@Param("gid") Integer gid);

    /**
     * 设置库存
     * @param gid
     * @param stock
     * @return
     */
    @Update("update goods set stock=#{stock} where gid=#{gid}")
    boolean setGoodsStock(@Param("gid") Integer gid,@Param("stock") Integer stock);

    /**
     * 更新库存
     * @param gid
     * @param stock
     * @return
     */
    @Update("update goods set stock= stock-#{stock} where gid=#{gid}")
    boolean updateGoodsStock(@Param("gid") Integer gid,@Param("stock") Integer stock);
}
